/* Hybrid System Abstractor
 *
 * Copyright (c) 2013, Fortiss GmbH - An-Institut TU Muenchen
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fortiss.util;

import javax.xml.bind.annotation.*;
import java.util.*;



@XmlRootElement
public class ListWrapper<T>
{
    @XmlElement
    private List<T> list;
   
    public ListWrapper()    {}
   
    public ListWrapper(int initialCapacity)
    {
        this.list = new ArrayList<T>();
    }
   
    public ListWrapper(List<T> l)
    {
        this.list = l;
    }
   
    public T get(int index)
    {
        return list.get(index);
    }
   
    public boolean add(T e)
    {
        return list.add(e);
    }
   
    public T set(int index, T e)
    {
        return list.set(index, e);
    }
    
    public int size()
    {
        return list.size();
    }
    
    public List<T> unwrap()
    {
        return list;
    }
   
    @Override
    public boolean equals(Object o)
    {
        if (o instanceof ListWrapper){
            @SuppressWarnings("unchecked") 
            ListWrapper lw = (ListWrapper) o;
            if (this.list==null)
                return false;
            else
                return this.list.equals(lw.list);
        }
        else if (o instanceof List){
            @SuppressWarnings("unchecked") 
            List l = (List) o;
            if (this.list==null)
                return false;
            else
                return this.list.equals(l);
        }
        else
            return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 71 * hash + (this.list != null ? this.list.hashCode() : 0);
        return hash;
    }
}
